package com.citas.server;


import java.util.ArrayList;

import com.citas.client.Getdata;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;


@SuppressWarnings("serial")
public class GetdataImpl extends RemoteServiceServlet implements Getdata {

	@Override
	public ArrayList<String[]> getaDatadb(String query){
			
		ArrayList<String[] > dr=  Modelo.getInstance().getData(query);
		
		return dr;		
	
	}

	@Override
	public Integer consultar(String user, String password) {
		String sql="SELECT contrasenia,idpersona FROM persona WHERE usuario='"+user+"';";
		ArrayList<String[] > dr=Modelo.getInstance().getData(sql);
		if(dr.size()==0)return new Integer(-1);
		else{
			String cad=dr.get(0)[0];
			if(cad.equals(password)){
				return new Integer(Integer.parseInt(dr.get(0)[1]));
				}
			else return new Integer(-1);
		}
	}

	@Override
	public ArrayList<String[]> getEstadoCivil() {
		return Modelo.getInstance().getData("select idestadocivil,descripcion FROM estadocivil");
	}

	@Override
	public Boolean existeUsuario(String user) {
		if(Modelo.getInstance().getData("SELECT usuario FROM persona WHERE usuario='"+user+"';").size()==0){
			return true;
		}
		return false;
	}

	@Override
	public ArrayList<String[]> getIdiomas() {
		ArrayList<String[]> li=new ArrayList<String[]>();
		String a[]={"es","Castellano"};
		String b[]={"qu","Quechua"};
		String c[]={"ay","Aymara"};
		String d[]={"in","Ingles"};
		li.add(a);
		li.add(b);
		//li.add(c);
		li.add(d);
		return li;		
	}

	@Override
	public Boolean registrar(ArrayList<String> a) {
		String sql="INSERT INTO persona(idestadocivil, dni, nombre, apellidopaterno,"+
				"apellidomaterno,dianacimiento, mesnacimiento, anhonacimiento, sexo,"+
				"gruposanguineo,factorrh, direccion, correo, estadoactual, contrasenia, usuario) "+
				"VALUES (";
		sql+=a.get(0)+",";
		sql+=a.get(1)+",";
		sql+="'"+a.get(2)+"',";//nombre
		sql+="'"+a.get(3)+"',";//paterno
		sql+="'"+a.get(4)+"',";
		sql+=a.get(5)+",";//dia
		sql+=a.get(6)+",";//mes
		sql+=a.get(7)+",";//anio
		sql+="'"+a.get(8)+"',";
		sql+="'"+a.get(9)+"',";
		sql+="'"+a.get(10)+"',";
		sql+="'"+a.get(11)+"',";
		sql+="'"+a.get(12)+"',";
		sql+="'"+a.get(13)+"',";
		sql+="'"+a.get(14)+"',";
		sql+="'"+a.get(15)+"');";System.out.println(sql);
		try {
			Modelo.getInstance().updateData(sql);
		} catch (Exception e) {
			return new Boolean(false);
		}
		
		return new Boolean(true);
	}
	
	public Integer updateDatadb(String query) {
		// TODO Auto-generated method stub
		return Modelo.getInstance().updateData(query);
	}

	@Override
	public ArrayList<String[]> getDatosUsuario(String a) {
		// TODO Auto-generated method stub
		String sql="SELECT * FROM persona WHERE idpersona="+a+";";
		return Modelo.getInstance().getData(sql);
	}
	
}
